package com.ruoyi.basedata.service.impl;

import java.util.List;
import java.util.Map;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.basedata.domain.ResponseMessage;
import com.ruoyi.common.core.web.domain.AjaxResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.basedata.mapper.MsgMapper;
import com.ruoyi.basedata.domain.Msg;
import com.ruoyi.basedata.service.IMsgService;

import javax.annotation.Resource;

/**
 * 消息通知Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-10-25
 */
@Service
public class MsgServiceImpl implements IMsgService 
{
    @Autowired
    private MsgMapper msgMapper;


    private Logger logger = LoggerFactory.getLogger(MsgServiceImpl.class);


    @Override
    public AjaxResult getMsg(Map map) {
        logger.info("FinerMsgServiceImpl    getMsg start....map: "+map);
        int pageNo = Integer.parseInt(map.get("pageNo").toString());
        int pageSize = Integer.parseInt(map.get("pageSize").toString());
        PageHelper.startPage(pageNo, pageSize);
        List<Msg> msgList = msgMapper.getMsg(map);
        logger.debug("FinerMsgServiceImpl    getMsg result....msgList: "+msgList);
        PageInfo<Msg> pageInfo = new PageInfo<>(msgList);
        return AjaxResult.success(pageInfo);
    }

    @Override
    public AjaxResult getUReadCount(int userId) {
        logger.info("FinerMsgServiceImpl    getUReadCount start...userId: "+userId);
        int count = msgMapper.getUReadCount(userId);
        logger.debug("FinerMsgServiceImpl    getUReadCount result...count: "+count);
        return AjaxResult.success(count);
    }

    @Override
    public AjaxResult updMsgStatus(int id) {
        logger.info("FinerMsgServiceImpl    updMsgStatus start...id: "+id);
        ResponseMessage responseMessage = new ResponseMessage();
        int count = msgMapper.updMsgStatus( id);
        logger.debug("FinerMsgServiceImpl    updMsgStatus result...count: "+count);
        if (count < 0) {
            logger.error("FinerMsgServiceImpl    updMsgStatus error...");
            responseMessage.setCode("500");
            return AjaxResult.success(responseMessage);
        }
        responseMessage.setCode("200");
        return AjaxResult.success(responseMessage);
    }
    /**
     * 查询消息通知
     * 
     * @param id 消息通知主键
     * @return 消息通知
     */
    @Override
    public Msg selectMsgById(Long id)
    {
        return msgMapper.selectMsgById(id);
    }

    /**
     * 查询消息通知列表
     * 
     * @param msg 消息通知
     * @return 消息通知
     */
    @Override
    public List<Msg> selectMsgList(Msg msg)
    {
        return msgMapper.selectMsgList(msg);
    }

    /**
     * 新增消息通知
     * 
     * @param msg 消息通知
     * @return 结果
     */
    @Override
    public int insertMsg(Msg msg)
    {
        return msgMapper.insertMsg(msg);
    }

    /**
     * 修改消息通知
     * 
     * @param msg 消息通知
     * @return 结果
     */
    @Override
    public int updateMsg(Msg msg)
    {
        return msgMapper.updateMsg(msg);
    }

    /**
     * 批量删除消息通知
     * 
     * @param ids 需要删除的消息通知主键
     * @return 结果
     */
    @Override
    public int deleteMsgByIds(Long[] ids)
    {
        return msgMapper.deleteMsgByIds(ids);
    }

    /**
     * 删除消息通知信息
     * 
     * @param id 消息通知主键
     * @return 结果
     */
    @Override
    public int deleteMsgById(Long id)
    {
        return msgMapper.deleteMsgById(id);
    }
}
